home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / arexxtutorial / archie18 / archie.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  4KB  |  150 lines

  1. /* Archie.rexx -- a backup utility by <CB> aka Christian Balzer
  2.    based on du.rexx by Larry Phillips.
  3.     _  _
  4.  / /  | \ \  <CB> aka Christian Balzer  - The Software Brewery -
  5. < <   |-<  > UUCP: decwrl!frambo.dec.com!cb OR cb@frambo.dec.com
  6.  \ \_ |_/ /  CIS : 71001,210 (be brief!) | Phone: +49 6150 4151 (CET!)
  7. ------------ Mail: Im Wingertsberg 45, D-6108 Weiterstadt, F.R.G.
  8.  
  9. Usage: [rx] Archie SOURCE DESTINATION [-options]
  10.  
  11. SOURCE and DESTINATION are valid AmigaDOS path's WITHOUT trailing
  12. slashes '/'.
  13. Valid options are: Currently none...
  14.  
  15. Archie will copy all files that don't have the archive bit set
  16. from SOURCE and it's subdirectories to DESTINATION. If these
  17. directories don't exist at DESTINATION, Archie will try to create
  18. them on the fly and thus preserving the original structure at SOURCE.
  19. After the file has been copied, it's archive bit will be set.
  20.  
  21. Note: The files will be copied with 'CLONE' flag of the COPY command
  22. set. This of course only works with the 1.3 version of COPY.
  23. In this version of Archie, filenames or directories containing blanks
  24. (like "My Dir:My File"), are NOT supported!
  25. In version 1.7 the form "a add" for Protect was changed to "add a" to
  26. support the ARP 1.3 protect command which isn't fully compatible.  */
  27.  
  28. /* This is Public Domain, read the source and learn */
  29.  
  30. say 'Archie 1.8 (05-May-89) by <CB>'
  31.  
  32. /* open the Rexx support library */
  33.  
  34. if ~show('L',"rexxsupport.library") then do
  35.    if addlib('rexxsupport.library',0,-30,0) then
  36.       say 'added rexxsupport.library'
  37.    else do;
  38.       say 'support library not available'
  39.       exit 10
  40.       end
  41.    end
  42.  
  43. address command
  44. call pragma 'priority',-1
  45.  
  46. arg rein
  47.  
  48. /* The parser */
  49. copt = 'clone'
  50.  
  51. if words(rein) < 2 then do
  52.         say 'Come on, gimme a SOURCE *AND* a DESTINATION path'
  53.         say 'Ya better try again... Bye!'
  54.         exit 10
  55. end
  56.  
  57.  
  58. root = subword(rein,1,1)
  59. dest = subword(rein,2,1)
  60.  
  61. if ~ exists(root) then do
  62.         say 'Source not found'
  63.         say 'Exiting... Check your parameters'
  64.         exit 10
  65. end
  66.  
  67. if ~ exists(dest) then do
  68.         say 'Destination not found'
  69.         say 'I''ll try to create it for you...'
  70.         'makedir 'dest
  71.         if ~ exists(dest) then do
  72.                 say 'Exiting... Check your parameters'
  73.                 exit 15
  74.         end
  75.         say 'Created 'dest
  76. end
  77.  
  78. if right(root,1) ~= ':' then
  79.   root = root || '/'
  80. if root = '/' then root = ''
  81.  
  82. if right(dest,1) ~= ':' then
  83.   dest = dest || '/'
  84. if dest = '/' then dest = ''
  85.  
  86. rlen = length(root)
  87.  
  88. bytes = 0
  89. blocks = 0
  90. files = 0
  91. dircount = 1
  92.  
  93. say 'Archie is doing it''s job on 'root
  94.  
  95. call dolist(root)
  96.  
  97. say 'Archived:' bytes 'bytes,' blocks 'blocks, ',
  98. files 'files in a total 'dircount' directories.'
  99. say
  100. exit 0
  101.  .
  102.  
  103. /* The real thing */
  104.  
  105. dolist: procedure expose bytes blocks files dest rlen dircount copt
  106. parse arg x
  107. contents = showdir(x);
  108. do i = 1 to words(contents)
  109.   temp = x || word(contents,i)
  110.   flen = length(word(contents,i))
  111.   type = statef(temp)
  112.   if word(type,1) = 'FILE' then
  113.     do
  114.       if substr(word(type,4),4,1) = '-' then
  115.         do
  116.                 target = dest || right(temp,(length(temp) - rlen))
  117.                 target = left(target,(length(target) - flen))
  118.                 'copy 'temp target copt
  119. /*              if RC > 0 then
  120.                   say 'Error archiving 'temp
  121.                 else */
  122.                 do
  123.                   files = files + 1
  124.                   bytes = bytes + word(type,2)
  125.                   blocks = blocks + word(type,3) + 1
  126.                   'protect 'temp 'add a'
  127. /*                if RC > 0 then
  128.                     say 'Error protecting 'temp
  129.                   else */
  130.                   say 'Archived: 'temp
  131.                 end
  132.         end
  133.     end
  134.   if word(type,1) ='DIR' then do
  135.         subdir = dest || right(temp,(length(temp) - rlen))
  136.         if ~ exists(subdir) then
  137.           do
  138.             'makedir' subdir
  139.             if ~ exists(subdir) then do
  140.               say 'Sorry... Exiting'
  141.               exit 20
  142.             end
  143.             say ' *** Created directory' subdir
  144.           end
  145.         call dolist(temp || '/')
  146.         dircount = dircount + 1
  147.   end
  148. end
  149. return
  150.